/*
 * 用户管理模块
 */
AdminUserCurd = Ext.extend(RockyGridCurd,{
	win:null,
	fp : null,
	baseUrl: 'adminuser.action',
	winCfg : {
		maximizable:true, 
		width:520,
		title : "用户详细信息"
	},	
	title:"系统用户管理",	
	trackMouseOver : false,
	loadMask:false, 
	autoWidth : false,		
	autoScroll:true,
	closable : true,	
	viewConfig : {
		forceFit : false
	},	
	constructor : function(config) {	
		var store = new Ext.data.JsonStore( {		
			id : "id",
			url : 'readUser.action',
			root : "data",
			totalProperty : "rowCount",
			remoteSort : false,
			fields : ["username","password","status","type","createTime","memo","area","role","areaId","roleId","id","realname","companyname" ,"companyplace","memberstate","paytype","membertype","type","type2","industryMajorId","industryMajor","companyRegPlace","companyRegMoney","companyCreateTime","brandMajor","companyWebsite","keyword","sex","telphone","fax","mobile","email","zip","job","companyDesc","roleName"],
			listeners:{
				beforeload: function() {
					var industryMajorFilterValue = (Ext.getDom('industryMajorIdFilter'))?Ext.getDom('industryMajorIdFilter').value:'-1';
					var roleFilterValue = this.roleFilter.getValue();					
					var keywordFilterValue = this.keywordFilter.getValue();
					store.baseParams.keywordFilterValue =keywordFilterValue||'';				
					store.baseParams.roleFilterValue =roleFilterValue||'';	
					store.baseParams.limit=20; 
				},scope:this
			}
		});		
		this.roleStore = new Ext.data.JsonStore( {
			autoLoad:true,
			id : "id",
			url : 'role.action?cmd=read',
			remoteSort : false,
			fields : ["id","rolename"],
			listeners:{
				load:function(store, records, options){			
			    	store.insert(0,new Ext.data.Record({'id':'-1','rolename':'所有角色'}, '-1'));
			    	this.roleFilter.setValue('-1');			    	   	
				},
				scope:this
			}
		}); 
		this.roleFilter = new Ext.form.ComboBox( { // select
			fieldLabel : 'select',
			editable : true,
			triggerAction : 'all',		
			valueField : 'id',
			displayField : 'rolename',
			mode : 'local',		
			store : this.roleStore
		});
		this.keywordFilter = new Ext.form.TextField( {
								width : 286,
								pressed : true,
								scope : this
		});
		var sm = new Ext.grid.CheckboxSelectionModel();	
		var cm = new Ext.grid.ColumnModel([ sm,new Ext.grid.RowNumberer({ width:30,header :"序号"}),{
				header : "用户名",
				sortable : false,
				width:200,
				dataIndex : "username"
			}, {
				header : "密码",
				sortable : true,width:100,				
				dataIndex : "password"
			}, {		
				header : "用户角色",
				sortable : true,width:200,				
				dataIndex : "role"			
			}, {
				header : "用户状态",
				sortable : true,width:100,				
				dataIndex : "status"
			}, {
				header : "所在地区",
				sortable : true,width:200,				
				dataIndex : "area"					
			}, {			
				header : "注册日期",
				sortable : false,width:200,				
				dataIndex : "createTime"			
			}]);
		cm.defaultSortable = true;
		Ext.apply(this, {
			cm :cm,
			store :  store,
			sm: sm,
			tbar : ['   ', {
				text : '添加',
				iconCls:'add',
				pressed : false,
				handler : this.create,
				scope : this
			}, '   ', {
				text : '修改',
				iconCls:'edit',			
				pressed : false,
				handler : this.edit,
				scope : this
			}, '   ', {
				text : '删除',
				iconCls:'remove',
				pressed : false,
				handler : this.removeData,
				scope : this
			}, '   ', {
				text : '刷新',
				iconCls:'refresh',
				pressed : false,
				handler : this.refresh,
				scope : this
			}, new Ext.Toolbar.Fill(),'-',
			'用户角色', this.roleFilter,'-',	
			'关键字: ', this.keywordFilter, 
			{
							text : '查询',
							iconCls:'search',
							pressed : true,
							handler : this.search,
							
							scope : this						
						}, {
							text : '重置',
							iconCls:'cancel',
							pressed : true,
							handler : this.onReset,						
							scope : this
						}, ''],			
			bbar : new Ext.PagingToolbar( {
				pageSize : 20,
				store : store,
				displayInfo : true,
				displayMsg : '显示{0}-{1}，共{2}条记录',
				emptyMsg : "没有可显示的记录！"
			})
		});
		AdminUserCurd.superclass.constructor.call(this, config);	
	},
	onReset:function(){
		this.roleFilter.setValue("");
		this.keywordFilter.setValue("");
	},
	createForm : function() {
		var formPanel = new Ext.form.FormPanel( {
		  	autoScroll:true,
			frame : true,
			border:false,			
			bodyStyle : 'position:relative;margin:15px 0 0px 15px',
			labelAlign : 'left',
			width : 500,
			height : 250,
			defaults : {
				width : 350
			},
			items : [{
					xtype : "hidden",
					name : "id"			
            },{  
					xtype : "hidden",
					name : "areaId"
            },{            	
		        	xtype:"combo",
					fieldLabel : '用户角色',
					allowBlank : false,
					editable : false,
					triggerAction : 'all',
					emptyText : '请选择',			
					valueField : 'id',
					displayField : 'rolename',
					mode : 'local',
					store : this.roleStore,				
					name:"roleId",
					hiddenName:"roleId" ,
					anchor:'95%' 
   },{
		          	xtype:"treecombo",
					fieldLabel : "所属地区",
					allowBlank : true,
					emptyText : '请选择',					
					name : "area",
					anchor:'95%',
					editable : false,								
					tree : new Ext.tree.TreePanel( {						
						border : false,
						rootVisible:true,
						root : new Ext.tree.AsyncTreeNode( {
							id : "-1",
							text : "未归类",
							expanded : true,							
							loader : new RockyCurd.TreeLoader( {
								dataUrl : "genAreaTree.action",
								expanded : true,
								nodeMeta : {
									id : 'id',
									text : 'name'
								}
							})
						}),
						listeners : {
							click : function( node,  e ) {
									var combo = this.fp.find('name','area')[0];
									var hidden = this.fp.find('name','areaId')[0];
									combo.setValue(node.text);
									hidden.setValue(node.id);
									combo.collapse();
									return true;
							},	
							scope:this
						}
					})					  
            },{   
		        	xtype:"combo",
					fieldLabel : '是否有效',
					allowBlank : false,
					editable : false,
					triggerAction : 'all',
					emptyText : '请选择',			
					valueField : 'value',
					displayField : 'key',
					mode : 'local',
					store : new Ext.data.SimpleStore( {
						fields : ["key", "value"],
						data : [['active', 'active'], ['deactive', 'deactive']]
					}),				
					name:"status",
					hiddenName:"status",
					anchor:'95%' 
            },{
			        xtype:'textfield',				      
			        fieldLabel:'用户名',
			        allowBlank : false,
			        name: 'username',			              
			        anchor:'95%'   
            },{             	
			        xtype:'textfield',				      
			        fieldLabel:'密码',
			        allowBlank : false,
			        name: 'password',			              
			        anchor:'95%'   			        
	        },{        	
			        xtype:'textarea',				      
			        fieldLabel:'备注信息',
			        name: 'memo',
			        anchor:'95%'
	        }]
		});
		return formPanel;
	}
});